package com.mew.lobby.handler.gold;


import com.mew.common.dc.redis.UserProfileRedisService;
import com.mew.common.entity.user.Profile;
import com.mew.common.entity.user.User;
import com.mew.common.exception.ResponseCode;
import com.mew.common.rest.bo.MewSession;
import com.mew.common.rest.gold.TranRequest;
import com.mew.common.rest.gold.TranResponse;
import com.mew.common.rest.user.UserMoneyResponseMessage;
import com.mew.lobby.annotation.LobbyHandler;
import com.mew.lobby.handler.sms.SMSValidService;
import com.mew.lobby.net.LobbyHandlerMapCmdType;
import com.mew.lobby.net.MewHandler;
import com.mew.lobby.provide.GoldFeignService;
import com.zebra.remoting.protocol.ZebraCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@LobbyHandler(LobbyHandlerMapCmdType.Tran)
public class TranHandler implements MewHandler<TranRequest> {

    @Autowired
    private GoldFeignService goldFeignService;

    @Autowired
    private SMSValidService smsValidService;

    @Autowired
    private UserProfileRedisService userProfileRedisService;


    @Override
    public void handle(ZebraCommand<TranRequest> zebraCommand, MewSession session) {
        long userId = zebraCommand.getUserId();
        long toUid = zebraCommand.getRequest().getToUid();
        long goldNumber = zebraCommand.getRequest().getGoldNumber();


        TranResponse message = goldFeignService.tran(userId, toUid, goldNumber);

        if (message.getStatus()== ResponseCode.Success.code()){
            zebraCommand.sendMessage(message);
            return;
        }

        zebraCommand.sendFailureCode(message.getStatus());
    }
}
